package com.sam.im.heiqun.uis.activities;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.sam.im.heiqun.R;
import com.melink.bqmmsdk.bean.Emoji;
import com.melink.bqmmsdk.sdk.BQMM;
import com.melink.bqmmsdk.sdk.BQMMMessageHelper;
import com.melink.bqmmsdk.sdk.IBqmmSendMessageListener;
import com.melink.bqmmsdk.ui.keyboard.BQMMKeyboard;
import com.melink.bqmmsdk.widget.BQMMEditView;
import com.melink.bqmmsdk.widget.BQMMMessageText;
import com.melink.bqmmsdk.widget.BQMMSendButton;

import org.json.JSONArray;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TestBQAcivity extends AppCompatActivity {

    @BindView(R.id.chatbox_send)
    BQMMSendButton chatboxSend;
    @BindView(R.id.chatbox_message)
    BQMMEditView chatboxMessage;
    @BindView(R.id.chat_msg_input_box)
    BQMMKeyboard chatMsgInputBox;
    @BindView(R.id.bv_messagetext)
    BQMMMessageText bvMessagetext;
    private BQMM bqmm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_bqacivity);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        bqmm = BQMM.getInstance();
//注册UI中的EditView、Keyboard和SendButton
        bqmm.setEditView(chatboxMessage);
        bqmm.setKeyboard(chatMsgInputBox);
        bqmm.setSendButton(chatboxSend);
        bqmm.load();
        bqmm.setBqmmSendMsgListener(new IBqmmSendMessageListener() {
            @Override
            public void onSendFace(Emoji face) {
                JSONArray msgCodes = BQMMMessageHelper.getFaceMessageData(face);
                //bvMessagetext.showMessage(BQMMMessageHelper.getFaceMessageString(face),msgCodes,);
               // sendFaceText(BQMMMessageHelper.getFaceMessageString(face),msgCodes,FACETYPE);
                bvMessagetext.showMessage(BQMMMessageHelper.getFaceMessageString(face),BQMMMessageText.FACETYPE,msgCodes);
                Log.i("info","这个啥");//纯表情  gif图
            }

            @Override
            public void onSendMixedMessage(List<Object> emojis, boolean isMixedMessage) {
                String msgString = BQMMMessageHelper.getMixedMessageString(emojis);
                //判断一下文本中是否含有非Unicode表情
                //小表情都是Unicode字符，因此在消息中只含有文字和小表情的时候，这里仍然是false
                if(isMixedMessage){
                    JSONArray msgCodes = BQMMMessageHelper.getMixedMessageData(emojis);
                    bvMessagetext.showMessage(msgString,BQMMMessageText.EMOJITYPE,msgCodes);
                    Log.i("info","那个啥");
                   // sendFaceText(msgString,msgCodes, 0);
                }else{
                    Log.i("info","这个那个啥");//文字加小表情或者小表情
                    bvMessagetext.setText(msgString);
                    //sendText(msgString);
                }
            }
        });
    }

    @OnClick({R.id.chatbox_send, R.id.chatbox_message, R.id.chat_msg_input_box})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.chatbox_send:
                break;
            case R.id.chatbox_message:
                break;
            case R.id.chat_msg_input_box:
                break;
        }
    }
    @Override
    protected void onDestroy() {
        //关闭SDK
        bqmm.destroy();
        super.onDestroy();
    }
}
